<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改医院信息')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-baseinfo-edit" th:object="${baseinfo}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label">logo：</label>
                <div class="col-sm-8">
                    <input name="logo" th:value="*{logo}" class="form-control" type="hidden" id="logoVal"/>
                    <img th:src="*{logo}" style="width: 80px;height: 100px;" id="logoImg">
                    <input type="file" class="" id="logo" accept="image/*" onchange="uploadFile()"/>
                </div>
            </div>
<!--            <div class="form-group">-->
<!--                <label class="col-sm-3 control-label">医院名称：</label>-->
<!--                <div class="col-sm-8">-->
<!--                    <input name="name" th:field="*{name}" class="form-control" type="text">-->
<!--                   -->
<!--                        <select id="name" name="registerId" class="form-control">-->
<!--                            <option th:each="register : ${registerinfoList}" th:text="${register['name']}" th:value="${register['id']}" th:field="*{registerId}"></option>-->
<!--                        </select>-->
<!--                   -->
<!--                </div>-->
<!--            </div>-->
            <div class="form-group">
                <label class="col-sm-3 control-label">医院名称：</label>
                <div class="col-sm-8">
                    <select id="name" name="name" class="form-control m-b">
                        <option th:each="hospital : ${HospitalinfoList}" th:text="${hospital['hospitalName']}" th:field="*{name}" th:value="${hospital['hospitalName']} "  th:attr="data-hospital-id=${hospital['hospitalId']}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">医院介绍：</label>
                <div class="col-sm-8">
                    <textarea name="introduce" class="form-control">[[*{introduce}]]</textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">营业时间：</label>
                <div class="col-sm-8">
                    <input name="bussinessTime" th:field="*{bussinessTime}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">医院电话：</label>
                <div class="col-sm-8">
                    <input name="phone" th:field="*{phone}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">所在地区：</label>
                <div class="col-sm-8">
                    <select id="areaName" name="areaName" class="form-control">
<!--                        <option th:each="area : ${areainfosList}" th:text="${area['areaName']}" th:value="${area['areaName']}" th:field="*{areaName}"></option>-->
                        <option th:each="area : ${areainfosList}" th:text="${area['areaName']}" th:value="${area['areaName']}" th:field="*{areaName}" th:attr="data-area-id=${area['areaId']}"></option>

                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">地址：</label>
                <div class="col-sm-8">
                    <textarea name="address" class="form-control">[[*{address}]]</textarea>
                </div>
            </div>
<!--            <div class="form-group">-->
<!--                <label class="col-sm-3 control-label is-required">经度：</label>-->
<!--                <div class="col-sm-8">-->
<!--                    <input name="longitude" th:field="*{longitude}" class="form-control" type="text" required>-->
<!--                </div>-->
<!--            </div>-->
<!--            <div class="form-group">-->
<!--                <label class="col-sm-3 control-label is-required">纬度：</label>-->
<!--                <div class="col-sm-8">-->
<!--                    <input name="latitude" th:field="*{latitude}" class="form-control" type="text" required>-->
<!--                </div>-->
<!--            </div>-->
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script type="text/javascript">
        var prefix = ctx + "register/baseinfo";
        $("#form-baseinfo-edit").validate({
            focusCleanup: true
        });

        function uploadFile() {
            var formData = new FormData();
            if ($('#logo')[0].files[0] == null) {
                return false;
            }
            formData.append('file', $('#logo')[0].files[0]);
            var flag = true;
            $.ajax({
                url: ctx + "common/upload",
                type: 'post',
                cache: false,
                data: formData,
                processData: false,
                contentType: false,
                async:false,
                dataType: "json",
                success: function (result) {
                    if (result.code == web_status.SUCCESS) {
                        var data = result.fileName;
                        $("#logoVal").val(data);
                        $("#logoImg").attr("src", data);
                    }else {
                        $.modal.alertError(result.msg);
                    }
                },
                error: function(error) {
                    $.modal.alertWarning("图片上传失败。");
                }
            });
            return flag;
        }

        function submitHandler() {
            if ($.validate.form()) {
                var data = $("#form-baseinfo-edit").serializeArray();
                // 获取所选选项的值和相关hospitalId
                var hospitalSelect = $('select[name="name"]');
                var selectedOption = hospitalSelect.find('option:selected');
                var selectedValue = selectedOption.val();
                var selectedHospitalId = selectedOption.data('hospital-id');

                var hospitalSelect1 = $('select[name="areaName"]');
                var selectedOption1 = hospitalSelect1.find('option:selected');
                var selectedValue1 = selectedOption1.val();
                var selectedHospitalId1 = selectedOption1.data('area-id');
                // alert(selectedValue)
                // alert(selectedHospitalId)
                data.push({"name": "hospitalId", "value": selectedHospitalId});
                data.push({"name": "areaId", "value": selectedHospitalId1});
                $.operate.save(prefix + "/edit", data);
            }
        }
    </script>
</body>
</html>
